import type { ITestPaper } from "./type"
import type { ITestItem } from "../test-item"

export class TestPaper implements ITestPaper {
    name: string
    description: string
    items: ITestItem[]
    constructor(name: string, description: string, items: ITestItem[] = []) {
        this.name = name
        this.description = description
        this.items = items
    }

    addTestItem(testItem: ITestItem, index: number = -1) {
        if (index >= 0) this.items.splice(index, 0, testItem)
        else this.items.push(testItem)
    }

    removeTestItem(testItem: ITestItem) {
        this.items.splice(this.items.indexOf(testItem), 1)
    }

    getCategorys(): string[] {
        return Array.from(new Set(this.items.map(item => item.category)))
    }
}

export function createTestPaper(name: string, description: string, items: ITestItem[] = []): ITestPaper {
    return new TestPaper(name, description, items)
}